home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
251_01
/
objects.adi
< prev
next >
Wrap
Text File
|
1987-10-27
|
13KB
|
556 lines
; This is the object-oriented runtime package
; by David Betz
; July 19, 1986
; ********************
; PROPERTY DEFINITIONS
; ********************
; These properties will be used for connections between locations
(property
north ; the location to the north
south ; the location to the south
east ; the location to the east
west ; the location to the west
up ; the location above
down) ; the location below
; Basic object properties
(property
initial-location ; the initial location of a "thing"
description ; the "long" description of a location
short-description) ; the "short" description of a location
; Connection properties
(property
parent ; the parent of an object
sibling ; the next sibling of an object
child) ; the first child of an object
; Location properties
(property
visited) ; true if location has been visited by player
; Portal properties
(property
closed ; true if the portal is closed
locked ; true if the portal is locked
key ; key to unlock the portal
other-side) ; the other portal in a pair
; **********************
; VOCABULARY DEFINITIONS
; **********************
; Some abbreviations for common commands
(synonym north n)
(synonym south s)
(synonym east e)
(synonym west w)
(synonym inventory i)
; Define the basic vocabulary
(conjunction and)
(article the that)
; ********************
; VARIABLE DEFINITIONS
; ********************
(variable
curloc ; the location of the player character
%actor ; the actor object
%dobject ; the direct object
%iobject) ; the indirect object
; *********************
; CONNECTION PRIMITIVES
; *********************
; Connect an object to a parent
(define (connect p c)
(setp c parent p)
(setp c sibling (getp p child))
(setp p child c))
; Connect all objects to their initial parents
(define (connect-all &aux obj maxp1 par)
(setq obj 1)
(setq maxp1 (+ $ocount 1))
(while (< obj maxp1)
(if (setq par (getp obj initial-location))
(connect par obj))
(setq obj (+ obj 1))))
; Disconnect an object from its current parent
(define (disconnect obj &aux this prev)
(setq this (getp (getp obj parent) child))
(setq prev nil)
(while this
(if (= this obj)
(progn
(if prev
(setp prev sibling (getp this sibling))
(setp (getp this parent) child (getp this sibling)))
(setp this parent nil)
(return)))
(setq prev this)
(setq this (getp this sibling))))
; Print the contents of an object (used by "look")
(define (print-contents obj prop &aux desc)
(setq obj (getp obj child))
(while obj
(if (setq desc (getp obj prop))
(progn
(print " ")
(print desc)))
(setq obj (getp obj sibling))))
; List the contents of an object (used for "inventory")
(define (list-contents obj prop &aux desc)
(setq obj (getp obj child))
(while obj
(if (setq desc (getp obj prop))
(progn
(print "\t")
(print desc)
(terpri)))
(setq obj (getp obj sibling))))
; ************************
; OBJECT CLASS DEFINITIONS
; ************************
; ***********************
; The "basic-thing" class
; ***********************
(object basic-thing
(property
parent nil ; the parent of this object
sibling nil)) ; the next sibling of this object
; ***************************
; The "location" object class
; ***************************
(object location
(property
child nil ; the first object in this location
visited nil) ; has the player been here yet?
(method (knock? obj)
T)
(method (enter obj)
(connect self obj)
T)
(method (leave obj dir &aux loc)
(if (setq loc (getp self dir))
(if (send loc knock? obj)
(progn
(disconnect obj)
(send loc enter obj)))
(progn
(print "There is no exit in that direction.\n")
nil)))
(method (describe)
(if (getp self visited)
(print (getp self short-description))
(progn
(print (getp self description))
(print-contents self description)
(setp self visited t)))
(terpri)))
; ******************
; The "portal" class
; ******************
(basic-thing portal
(method (knock? obj)
(if (getp self closed)
(progn
(print "The ")
(print (getp self short-description))
(print " is closed!\n")
nil)
T))
(method (enter obj)
(connect (getp (getp self other-side) parent) obj))
(method (open)
(if (not (getp self closed))
(progn
(print "The ")
(print (getp self short-description))
(print " is already open!\n")
nil)
(if (getp self locked)
(progn
(print "The ")
(print (getp self short-description))
(print " is locked!\n")
nil)
(progn
(setp self closed nil)
T))))
(method (close)
(if (getp self closed)
(progn
(print "The ")
(print (getp self short-description))
(print " is already closed!\n")
nil)
(progn
(setp self closed T)
T)))
(method (lock thekey)
(if (not (getp self closed))
(progn
(print "The ")
(print (getp self short-description))
(print " is not closed!\n")
nil)
(if (getp self locked)
(progn
(print "The ")
(print (getp self short-description))
(print " is already locked!\n")
nil)
(if (not (= thekey (getp self key)))
(progn
(print "It doesn't fit the lock!\n")
nil)
(progn
(setp self locked t)
T)))))
(method (unlock thekey)
(if (not (getp self closed))
(progn
(print "The ")
(print (getp self short-description))
(print " is already open!\n")
nil)
(if (not (getp self locked))
(progn
(print "The ")
(print (getp self short-description))
(print " is not locked!\n")
nil)
(if (not (= thekey (getp self key)))
(progn
(print "It doesn't fit the lock!\n")
nil)
(progn
(setp self locked nil)
T))))))
; *****************
; The "actor" class
; *****************
(basic-thing actor
(property
child nil) ; the first "thing" carried by this actor
(method (move dir)
(send (getp self parent) leave self dir))
(method (take obj)
(disconnect obj)
(connect self obj))
(method (drop obj)
(disconnect obj)
(connect (getp self parent) obj))
(method (carrying? obj)
(= (getp obj parent) self))
(method (inventory)
(cond ((getp %actor child)
(print "You are carrying:\n")
(list-contents %actor short-description))
(T (print "You are empty-handed.\n")))))
; *****************
; The "thing" class (things that can be taken)
; *****************
(basic-thing thing
(class-property
takeable t))
; ****************************
; The "stationary-thing" class (things that can't be moved)
; ****************************
(basic-thing stationary-thing)
; ***********************
; MISCELLANEOUS FUNCTIONS
; ***********************
; Complain about a noun phrase
(define (complain head n tail)
(print head)
(print-noun n)
(print tail)
(abort))
; Find an object in a location
(define (findobject loc n &aux this found)
(setq this (getp loc child))
(setq found nil)
(while this
(if (match this n)
(if found
(complain "I don't know which " n " you mean!\n")
(setq found this)))
(setq this (getp this sibling)))
found)
; Find an object in the player's current location
; (or in the player's inventory)
(define (in-location n &aux obj)
(if (or (setq obj (findobject curloc n))
(setq obj (findobject %actor n)))
obj
(complain "I don't see a " n " here!\n")))
; Find an object